package com.rest.demo.functional.concurrent;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Administrator
 * @decription
 * @Date 2018-01-31 10:43
 */
public class concurrentMap {
    public static void main(String[] args) {
        Map<String,String> conMap = new ConcurrentHashMap<String,String>();
        conMap.put("one","first");
        conMap.put("two","second");

        conMap.forEach((k,v) -> System.out.format("key:%s,value:%s\n",k,v));

        String value = conMap.putIfAbsent("one","third");
        System.out.println(value);

        System.out.println(conMap.getOrDefault("three","none value"));

        conMap.replaceAll((k,v) -> "one".equals(k) ? "one" : v);

        conMap.forEach((k,v) -> System.out.format("key:%s,value:%s\n",k,v));

        conMap.compute("one",(k,v) -> v + v);

        conMap.forEach((k,v) -> System.out.format("key:%s,value:%s\n",k,v));
    }
}
